package com.yunmang.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.yunmang.R;
import com.yunmang.app.AppConstant;

import java.util.List;

/**
 * 作者 : bean on 2017/4/7/0007.
 * 注释 :
 */
public class MyHomeAdapter extends BaseAdapter {
    private  Context context;

    public MyHomeAdapter(Context context) {
        this.context = context;
    }

    private void exit() {
        System.exit(0);
    }

    @Override
    public int getCount() {
        if(TextUtils.isEmpty(AppConstant.type)){
            exit();
            return 0;
        }
        if(AppConstant.type.equals("2")){//分拨中心
            return 6;
        }else if(AppConstant.type.equals("1")){//总公司 = 1,
            return 6;
        }else{
            return 6;
        }
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHolder holder ;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.gv_home_item,null);
            holder = new MyHolder();
            holder.iv_item_icon = (ImageView) convertView.findViewById(R.id.iv_item_icon);
            holder.tv_item_title = (TextView) convertView.findViewById(R.id.tv_item_title);
            holder.ll = (LinearLayout) convertView.findViewById(R.id.ll_top_gridview);

            convertView.setTag(holder);
        }else {
            holder = (MyHolder) convertView.getTag();
        }

        if((position+1)%2==0){
            holder.ll.setBackgroundColor(context.getResources().getColor(R.color.light_gray));
        }else{
            holder.ll.setBackgroundColor(context.getResources().getColor(R.color.white));
        }

        if(AppConstant.type.equals("2")){//分拨中心
            switch (position){
                case 0:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydgl);
                    holder.tv_item_title.setText("运单管理");
                    break;
                case 1:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_apdh);
                    holder.tv_item_title.setText("按票到货");
                    break;
                case 2:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_gxys);
                    holder.tv_item_title.setText("干线运输");
                    break;
                case 3:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydgz);
                    holder.tv_item_title.setText("运单跟踪");
                    break;
                case 4:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ycgl);
                    holder.tv_item_title.setText("异常管理");
                    break;
                case 5:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_pcgl);
                    holder.tv_item_title.setText("批次管理");
                    break;
            }
        }else if(AppConstant.type.equals("1")){//总公司 = 1,
            switch (position){
                case 0:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydsl);
                    holder.tv_item_title.setText("运单受理");
                    break;
                case 1:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_gxys);
                    holder.tv_item_title.setText("干线运输");
                    break;
                case 2:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_apdh);
                    holder.tv_item_title.setText("按票到货");
                    break;
                case 3:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_psqs);
                    holder.tv_item_title.setText("派送签收");
                    break;
                case 4:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydgl);
                    holder.tv_item_title.setText("运单管理");
                    break;
                case 5:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydgz);
                    holder.tv_item_title.setText("运单跟踪");
                    break;
                case 6:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ycgl);
                    holder.tv_item_title.setText("异常管理");
                    break;
                case 7:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_pcgl);
                    holder.tv_item_title.setText("批次管理");
                    break;
            }
        }else{//分公司
            switch (position){
                case 0:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydsl);
                    holder.tv_item_title.setText("运单受理");
                    break;
                case 1:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_gxys);
                    holder.tv_item_title.setText("干线运输");
                    break;
                case 2:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_apdh);
                    holder.tv_item_title.setText("按票到货");
                    break;
                case 3:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_psqs);
                    holder.tv_item_title.setText("派送签收");
                    break;
                case 4:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydgl);
                    holder.tv_item_title.setText("运单管理");
                    break;
                case 5:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ydgz);
                    holder.tv_item_title.setText("运单跟踪");
                    break;
                case 6:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_ycgl);
                    holder.tv_item_title.setText("异常管理");
                    break;
                case 7:
                    holder.iv_item_icon.setImageResource(R.mipmap.icon_pcgl);
                    holder.tv_item_title.setText("批次管理");
                    break;
            }
        }
        return convertView;
    }


    private class MyHolder {
        public ImageView iv_item_icon;
        public TextView tv_item_title;
        public LinearLayout ll;
    }
}
